#include<iostream>
#include<arbb.hpp>
#include<stdio.h>
#include<cstdlib>
#include<sys/time.h>
using namespace arbb;

int main()
{
  // Partial Array Building Blocks code for Pi computation
  int NSTEPS=10000;
  f32 step = 1.0 / NSTEPS;
  timeval tim;
  dense<f32> I = static_cast< dense<f32> >(indices<i32>(0, NSTEPS, 1));
  gettimeofday(&tim, NULL);
  double t1=tim.tv_sec+(tim.tv_usec/1000000.0);
  dense<f32> X = (I + 0.5) * step;
  dense<f32> partial = 4.0  / (X * X + 1.0);
  f32 pi= step * add_reduce(partial);
  gettimeofday(&tim, NULL);
  double t2=tim.tv_sec+(tim.tv_usec/1000000.0);
  printf("%.6lf seconds elapsed\n", t2-t1);
  std::cout<<arbb::value(pi)<<"\n";
  return 0;
}
